import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter/material.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/TwoLabelItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/labelSelectItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/InputWidget.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/NavigationBar.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:heyangkuaidai/FrameWorkModule/Utils/PublicBottomMenu.dart';
import 'dart:convert';
import 'package:flutter/gestures.dart';
import 'package:clipboard/clipboard.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanSignFinshPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanBindCardPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/FaceRecPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanProtocalPage.dart';

class LoanContractSignPage extends StatefulWidget {

  @override
  _LoanContractSignPageState createState() => _LoanContractSignPageState();
}

class _LoanContractSignPageState extends State<LoanContractSignPage> {
  String hintText = "请选择借款用途";
  bool isfinsh =false;
  String finshText;
  bool useFlag;
  TapGestureRecognizer _tapPressRecognizer;
  final ScrollController _scrollController = ScrollController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    finshText ='';
    useFlag =false;
    _tapPressRecognizer = TapGestureRecognizer();
  }
  @override
  Widget build(BuildContext context) {

    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Column(
        children: [
          SizedBox(height: MediaQuery.of(context).padding.top,),
          NavigationBar(false, title: "福祥e贷",),
          Container(
              width: ScreenUtil.screenWidth,
              height: ScreenUtil.screenHeight-MediaQuery.of(context).padding.top-ScreenUtil().setWidth(70),
              child:KeyboardAvoider(
                autoScroll: true,
                 child:ListView(
                   padding: EdgeInsets.only(top: 0,),
                   controller: _scrollController,
                   children: [
                     TwoLabelItem(title:"借款人  " ,hitText:"章*闯" ,),
                     TwoLabelItem(title:"身份证", hitText: "4309***********2123",),
                     TwoLabelItem(title:"合同金额", hitText: "200,000.00元",),
                     TwoLabelItem(title:"年利率", hitText: "4.65%",),
                     TwoLabelItem(title:"合同期限 ", hitText: "2021.05.01-2022.4.30",),
                     labelSelectItem(title: "银行卡号",isflag: true, hitText: "6213***********6149",onTapCallback:(){
                        Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanBindCardPage(),
                  ),
                );
                     },
                     ),
                     TwoLabelItem(title:"还款方式", hitText: "按月付息，到期还本",),
                     TwoLabelItem(title:"还款日期", hitText: "每月21日",),

                     labelSelectItem(title: "借款用途",hitText: hintText,onTapCallback:(){
                       var Sources = ['大额耐用','购车','装修','垫付租金'];
                       showModalBottomSheet(
                           context: context,
                           shape: RoundedRectangleBorder(
                               borderRadius: BorderRadiusDirectional.circular(0)
                           ),
                           builder: (BuildContext context){
                             return AlertBottomPage(
                               items: Sources,
                               chooseCallback: (index){
                                 setState(() {
                                   useFlag =true;
                                   hintText =Sources[index];
                                 });
                               },
                             );
                           });
                     }
                     ),
                     bottomWidget(),
                   ],
                 ) ,
              )
          ) ,

        ],
      ),
    );
  }
  Widget bottomWidget(){
    return Column(
      children: [
        SizedBox(
          height: ScreenUtil().setWidth(10),
        ),
        Container(
          height: ScreenUtil().setWidth(419),
          width:ScreenUtil.screenWidth ,
          color: Colors.white,
          child:Column(
            children: [
              SizedBox(height:ScreenUtil().setWidth(9) ,),
              Row(
                children: [
                  SizedBox(width: ScreenUtil().setWidth(15),),
                  Container(
                    width: ScreenUtil().setWidth(253),
                    height: ScreenUtil().setWidth(69),
                    child:Text("用途承诺声明：本人承诺贷款资金不用于股票、期货、金融衍生产品、股本权益性投资、购房以及国家有关法律、法规和规章禁止的其他消费与投资行为。",style: TextStyle(fontSize: ScreenUtil().setSp(12),color: Color(0xff737373)),textAlign: TextAlign.left,),
                  ),
                  SizedBox(width: ScreenUtil().setWidth(5),),
                  InkWell(
                    onTap: (){

                      FlutterClipboard.copy('用途承诺声明：本人承诺贷款资金不用于股票、期货、金融衍生产品、股本权益性投资、购房以及国家有关法律、法规和规章禁止的其他消费与投资行为。').then(( value ) => print('copied'));
                    },
                    child: Container(
                        decoration: BoxDecoration(
                            color:Color(0xffFFFFFF),
                            border: Border.all(
                                color: Color(0xff5CAFE5),
                                width: 1,
                                style: BorderStyle.solid
                            )
                        ),
                        width: ScreenUtil().setWidth(90),
                        height: ScreenUtil().setWidth(26),
                        child:Center(
                          child: Text("复制并粘贴",style: TextStyle(fontSize: ScreenUtil().setSp(13),color: Color(0xff5CAFE5)),textAlign: TextAlign.center,),
                        )
                    ) ,
                  ),

                ],
              ),
              SizedBox(height: ScreenUtil().setWidth(10),),
              Row(
                children: [
                  SizedBox(width: ScreenUtil().setWidth(17),),
                  Container(width: ScreenUtil().setWidth(358),height: ScreenUtil().setWidth(1),color:Color(0xffEBEBEB)),
                ],
              ),
              Container(
                height: ScreenUtil().setWidth(116),
                width: ScreenUtil.screenWidth,
                padding: EdgeInsets.only(left: ScreenUtil().setWidth(10)),
                child:InputWidget("请完整输入以上用途承诺声明",width:ScreenUtil.screenWidth-ScreenUtil().setWidth(17),numlines:4,maxlength: 1000,finishCallback:(text){
                   finshText =text;
                }),
              ),
              InkWell(
                  onTap: (){
                     Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new FaceRecPage(),
                  ),
                ).then((value) {
                      setState(() {
                        isfinsh =true;
                      });
                    });
                  },
                  child:Stack(
                    children: [
                      Container(
                        height: ScreenUtil().setWidth(62),
                        width: ScreenUtil.screenWidth,
                        color: Color(0xffF9FDFF),
                        child: Center(
                          child: Text(isfinsh?"人脸识别已通过":"请先进行人脸识别确认身份",style: TextStyle(fontSize: ScreenUtil().setSp(15),color:Color(0xff5CAFE5)),textAlign: TextAlign.center,),
                        ),
                      ),
                     isfinsh?Container():Positioned(
                          left: ScreenUtil().setWidth(292),
                          top: ScreenUtil().setWidth(23),
                          child: Container(
                            width: ScreenUtil().setWidth(18),
                            height: ScreenUtil().setWidth(18),
                            child: Image.asset("sources/yy/inArrown.png"),
                          )
                      )
                    ],
                  )
              ),
              SizedBox(height: ScreenUtil().setWidth(10),),
              Container(
                width: ScreenUtil.screenWidth,
                height: ScreenUtil().setWidth(70),
                child:Row(
                   children: [
                     SizedBox(width: ScreenUtil().setWidth(20),),
                     Container(
                       width: ScreenUtil().setWidth(257),
                       height: ScreenUtil().setWidth(40),
                       child:Text.rich(
                           TextSpan(
                               children: [
                                 TextSpan(text: "我已阅读并同意",style: TextStyle(fontSize: ScreenUtil().setSp(14),color: Colors.black)),
                                 TextSpan(text: "《最高额借款合同》",style: TextStyle(fontSize: ScreenUtil().setWidth(14),color: Color(0xff5CAFE5)),recognizer:
                                 _tapPressRecognizer..onTap =(){
                                    Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanProtocalPage(),
                  ),
                );
                                 }),
                                 TextSpan(text: "《还本付息授权书》",style: TextStyle(fontSize: ScreenUtil().setWidth(14),color: Color(0xff5CAFE5)),recognizer:
                                 _tapPressRecognizer..onTap =(){
                                    Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanProtocalPage(),
                  ),
                );
                                 }),

                               ]
                           )
                       ),
                     ),
                        SizedBox(width: ScreenUtil().setWidth(54),),
                        InkWell(
                           onTap: (){},
                           child:Container(
                             width: ScreenUtil().setWidth(24),
                             height: ScreenUtil().setWidth(24),
                             color: Colors.blue,
                             child:Image.asset("sources/yy/check.png") ,
                           ),
                         ),
                   ],
                )
              ),
              SizedBox(height: ScreenUtil().setWidth(21),),
              InkWell(
                onTap: (){
                  if(finshText.isEmpty||!useFlag||!isfinsh)return;
                   Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanSignFinshPage(),
                  ),
                );
                },
                child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(4),
                      color:Color(0xff41A5EE),
                    ),
                    width: ScreenUtil().setWidth(347),
                    height: ScreenUtil().setWidth(44),
                    child:Center(
                      child: Text("同意并确认签约",style: TextStyle(fontSize: ScreenUtil().setSp(17),color: Colors.white),textAlign: TextAlign.center,),
                    )
                ) ,
              ),
            ],
          ) ,
        )
      ],
    );
  }
}

